//
//  YYWindow.m
//  Pthread
//
//  Created by Yanyan Jiang on 2023/2/9.
//  Copyright © 2023 Yanyan Jiang. All rights reserved.
//

#import "YYWindow.h"

@implementation YYWindow

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
    if (self.userInteractionEnabled == NO||self.hidden == YES||self.alpha<=0.01) {
        return  nil;
    }
    
    if(![self pointInside:point withEvent:event]){
        return nil;
    }
    
    int count = (int)self.subviews.count;
    for (int i = (count-1); i >= 0; i--) {
        UIView *childView = self.subviews[i];
        CGPoint childPoint = [self convertPoint:point toView:childView];
        UIView *rView = [childView hitTest:childPoint withEvent:event];
        if(rView){
            return rView;
        }
    }
    
    //如果没有找到最合适的view,那么自己就是最适合的view
    return self;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    NSLog(@"%@----touch",[self class]);
    [super touchesBegan:touches withEvent:event];
}

@end
